#include "CTileManager.h"
#include "CLayer.h"
#include "CParticleManager.h"
#include "CObjectManager.h"
#include "CPlayer.h"

CTileManager::CTileManager()
{

}

CTileManager::~CTileManager()
{
}

CTileManager* CTileManager::GetInstance()
{
	/////////////////////////////////////////////
	//	Lazy Instantiation O.o
	static CTileManager instance;
	return &instance;
	//
	/////////////////////////////////////////////
}

void CTileManager::Init()
{

}

void CTileManager::Clear()
{
	for(unsigned int i = 0;i < m_vLayers.size();i++)
	{
		for(unsigned int j = 0; j < m_vLayers[i]->Tiles().size(); j++)
			delete m_vLayers[i]->Tiles()[j];
		m_vLayers[i]->Tiles().clear();
		delete m_vLayers[i];
	}
	m_vLayers.clear();
}

void CTileManager::Shutdown()
{

}

void CTileManager::Update(float fDelta)
{

}

void CTileManager::Render()
{
	////////////////////////////////////////////////////////////////////////////////////////
	//	Do rendering
	for(int i = 0; i < CTileManager::GetInstance()->LayerCount(); i++)
	{
		m_vLayers[i]->Render();
		if(i == 0)
		{
			CParticleManager::GetInstance()->Render();
			CObjectManager::GetInstance()->Render();
			CPlayer::GetInstance()->Render();
		}
	}
	//
	////////////////////////////////////////////////////////////////////////////////////////
}

void CTileManager::AddLayer(CLayer* pLayer)
{
	m_vLayers.push_back(pLayer);
}

void CTileManager::RemoveLayer(CLayer* pLayer)
{
	
}

void CTileManager::AddTile(int nLayer, CTile* pTile)
{
	m_vLayers[nLayer]->AddTile(pTile);
}